using UnityEngine;

namespace CHot
{
    public class CircleCollider : Collider
    {
        public float radius = 1;
        public Vector3 lastPos { get; private set; }
        public float scale { get; private set; }

        private Vector3 currPos;

        public override void Init()
        {
            base.Init();
            lastPos = currPos = transform.position;
            scale = 1;
            Transform parent = transform.parent;
            while (parent)
            {
                scale *= Mathf.Abs(parent.localScale.x);
                parent = parent.parent;
            }
        }

        public override void BeforeCheck()
        {
            base.BeforeCheck();
            lastPos = currPos;
            currPos = transform.position;
        }

#if UNITY_EDITOR
        void OnDrawGizmos()
        {
            Gizmos.color = Color.yellow;
            if (radius > 0)
            {
                float scale = this.scale;
                if (!Application.isPlaying)
                {
                    scale = 1;
                    Transform parent = transform.parent;
                    while (parent)
                    {
                        scale *= Mathf.Abs(parent.localScale.x);
                        parent = parent.parent;
                    }
                }
                Gizmos.DrawWireSphere(transform.position, radius * scale);
            }
        }
#endif
    }
}